<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>车辆管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">

    <style>
        .layui-hide{  /*最后的pic为字段的field*/
            height: 100%;
            max-width: 100%;
        }
        .layui-table-cell{
            height:auto !important;
        }
    </style>
</head>
<body>



<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">车辆管理</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">


                        <div class="layui-inline">
                            <label class="layui-form-label">导游名</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">车牌号</label>
                            <div class="layui-input-block">
                                <input type="text" name="car_code" id="car_code" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate" lay-size="lg">



                    </table>
                    <script type="text/html" id="test-pass">

                    </script>
                    <script type="text/html" id="test-table-operate-barDemo">

                        <a class="layui-btn layui-btn-normal layui-btn-xs" id="showImg" lay-event="showImg">车辆图片</a>
                        <a class="layui-btn layui-bg-green layui-btn-xs" lay-event="del">解绑</a>


                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set','layedit','upload'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate,
            upload = layui.upload
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Car/car')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'car_id',align:"center",title: 'ID'}
                ,{field:'name',align:"center",title: '导游名字'}
                ,{field:'car_model',align:"center",title: '车型'}
                ,{field:'car_code',align:"center",title: '车牌号'}
                ,{field:'car_money',align:"center",title: '钱数/天'}
                ,{field:'status',align:"center",title: '车辆状态',templet:function(d){
                        if(d.status == 0){
                            return "未使用";
                        }else if (d.eval_status == 1){
                            return "使用中";
                        }
                    }}
                ,{width:150,align:'center', title: '操作',fixed: 'right', toolbar: '#test-table-operate-barDemo'}

            ]]
            ,page: true
            ,limit: 20
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });

        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;

            if(obj.event === 'showImg') {
                if (!data.car_image) {
                    layer.msg('暂无图片', {time: 1000});
                    return false;
                }
                var img_src = data.car_image;
                var img_src_arr = img_src.split(',');

                var img_src_data = {};
                img_src_data.title = '评价图片';
                img_src_data.id = data.id;
                img_src_data.start = 0;
                img_src_data.data = [];

                var src = {};

                for (var i = 0; i < img_src_arr.length; i++) {
                    src = {};
                    var num = i + 1;
                    src.alt = '评价图片' + num;
                    src.pid = i;
                    src.src = img_src_arr[i];
                    src.thumb = img_src_arr[i];
                    console.log(src);
                    img_src_data.data.push(src);
                }
                console.log(img_src_data);
                layer.photos({
                    photos: img_src_data
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
            else if(obj.event === 'del'){
                layer.confirm('确认解绑此车辆吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Car/delCar')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.car_id},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            }
        });




        var $ = layui.$, active = {
            searchUserButton:function(){
                var name  = $('#name').val();

                var car_code = $('#car_code').val();
                table.reload('test-table-operate', {
                    where: {
                        name:name,
                        car_code:car_code,
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });

</script>

</body>
</html>